package edu.cmu.cs.webapp.ioms.actions;

import java.text.DateFormat;

import org.eclipse.jface.action.Action;
import org.eclipse.rwt.RWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;

import edu.cmu.cs.webapp.ioms.models.User;

public class LoginInfoAction extends Action implements
		ActionFactory.IWorkbenchAction {

	private IWorkbenchWindow workbenchWindow;
	private User user;

	public LoginInfoAction(IWorkbenchWindow workbenchWindow) {
		if (workbenchWindow == null) {
			throw new IllegalArgumentException();
		}
		this.workbenchWindow = workbenchWindow;
		user = (User) RWT.getSessionStore().getAttribute("uid");

		setText("Login Info");
		setId("login");
	}

	public void dispose() {

	}

	@Override
	public void run() {
		MessageBox dlg = new MessageBox(this.workbenchWindow.getShell());
		dlg.setText("Login Info");
		dlg
				.setMessage("Welcome "
						+ user.getName()
						+ "("
						+ user.getRole()
						+ "). You last login was at "
						+ DateFormat.getDateTimeInstance().format(
								user.getLast_login()));
		dlg.open();
	}
}
